home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgwnd10 / DIALOG.VBS < prev    next >
Encoding:
Text File  |  1998-09-14  |  3.4 KB  |  110 lines

  1. '--------------------------------------------------------------------------
  2. ' Dialog.vbs - Shows how to open and use dialogs from the WSH scripts.
  3. '
  4. ' REMARKS:
  5. ' - dialog resource must be located in the file that can be loaded with
  6. '   Win32 LoadLibrary() function (EXE, DLL, ...) or you can use empty
  7. '   dialog template located in the SGWINDOW.DLL module. In this case
  8. '   pass empty string as a first parameter for the DoModal method and
  9. '   string "DLG_EMPTY" as a dialog template name.
  10. '
  11. ' This file is part of the SG Window.
  12. ' Copyright (C) 1998 Stinga
  13. ' All rights reserved.
  14. '--------------------------------------------------------------------------
  15. option explicit
  16.  
  17. ' Messages
  18. const wm_CLOSE         = &H0010&
  19. const wm_INITDIALOG    = &H0110&
  20. const wm_COMMAND       = &H0111&
  21.  
  22. const LB_ADDSTRING     = &H0180&
  23. const LB_GETCURSEL     = &H0188&
  24. const LB_GETTEXT       = &H0189&
  25. const LB_GETTEXTLEN    = &H018A&
  26.  
  27. ' Global declarations
  28. Dim g, dlg, rc, sResult
  29. Dim edit, list
  30. Set dlg = WScript.CreateObject("SGWindow.Window", "dlg_")
  31. Set g   = WScript.CreateObject("SGWindow.Globals")
  32.  
  33. ' Show dialog
  34. rc = dlg.DoModal("DlgTest.dll", "TESTDIALOG", 100, 100)
  35.  
  36. Wscript.DisconnectObject dlg
  37. Set dlg = Nothing
  38. Set g = Nothing
  39.  
  40. MsgBox sResult
  41. WScript.Quit
  42.  
  43. '--------------------------------------------------------------------------
  44. ' Dialog window procedure
  45. '--------------------------------------------------------------------------
  46. Sub dlg_Message(msg, wParam, lParam, result)
  47.    result = 0
  48.    select case msg
  49.      case wm_INITDIALOG
  50.         Set edit = dlg.Children("{ID}100")
  51.         Set list = dlg.Children("{ID}105")
  52.         
  53.         ' Initialize dialog controls
  54.         edit.Text = "This is edit box"
  55.         list.SendMessage LB_ADDSTRING, 0, g.DataPtr("Item 1")
  56.         list.SendMessage LB_ADDSTRING, 0, g.DataPtr("Item 2")
  57.      
  58.      case wm_CLOSE
  59.         sResult = "Closed"
  60.         dlg.EndDialog 3
  61.         
  62.      case wm_COMMAND
  63.         Dim bHandled
  64.         bHandled = OnCommand(g.HighWord(wParam), g.LowWord(wParam), lParam)
  65.         if Not bHandled Then 
  66.            result = dlg.CallWindowProc(msg, wParam, lParam)
  67.         end if
  68.      
  69.      case else
  70.         result = dlg.CallWindowProc(msg, wParam, lParam)
  71.    end select
  72. End Sub
  73.  
  74. '--------------------------------------------------------------------------
  75. ' Handle dialog WM_COMMAND messages
  76. '--------------------------------------------------------------------------
  77. Private Function OnCommand(notifyCode, id, hwnd)
  78.    OnCommand = false
  79.    select case id
  80.       case 1 ' OK
  81.          ' Get text from the edit box
  82.          sResult = "Edit box text is '" & edit.Text & "'"
  83.          
  84.          ' Get slected item from the list box
  85.          sResult = GetSelText(list)
  86.           dlg.EndDialog 1
  87.            OnCommand = True
  88.           
  89.       case 2 ' CANCEL
  90.          sResult = "Canceled"
  91.           dlg.EndDialog 2
  92.            OnCommand = True
  93.           
  94.       case 100 ' EditBox
  95.    end select
  96. End Function
  97.  
  98. '--------------------------------------------------------------------------
  99. ' Return text of the selected item for the specified list box
  100. '--------------------------------------------------------------------------
  101. Private Function GetSelText(list)
  102.    Dim nSel, s
  103.    nSel = list.SendMessage(LB_GETCURSEL, 0, 0)
  104.    s = Space(list.SendMessage(LB_GETTEXTLEN, 0, 0) + 1)
  105.    list.SendMessage LB_GETTEXT, nSel, g.DataPtr(s)
  106.    GetSelText = s
  107. End Function
  108.  
  109.